/* Copyright (C) 2010 Fredrique Samuels, fredriquesamuels@gmail.com */

/*
  This program is free software; you can redistribute it and/or modify
  it under the terms of the GNU General Public License as published by
  the Free Software Foundation; either version 2 of the License, or
  (at your option) any later version.

  This program is distributed in the hope that it will be useful,
  but WITHOUT ANY WARRANTY; without even the implied warranty of
  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  GNU General Public License for more details.

  You should have received a copy of the GNU General Public License
  along with this program; if not, write to the Free Software
  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/

#ifndef TRI_TILE_H_
#define TRI_TILE_H_

#include "base/xmlnode.h"
#include "base/logging.h"
#include "glyph.h"

namespace tri
{


tri::TVector loadVector(tri::TXMLNode* node);

enum{
	//default
	TILE_BLANK,
	
	//tiles
	TILE_PLANE,
	TILE_INCLINED_NORTH,
	TILE_INCLINED_NORTH_EAST,
	TILE_INCLINED_EAST,
	TILE_INCLINED_SOUTH_EAST,
	TILE_INCLINED_SOUTH,
	TILE_INCLINED_SOUTH_WEST,
	TILE_INCLINED_WEST,
	TILE_INCLINED_NORTH_WEST,
	
	//objects
	OBJECT_MODEL,
	OBJECT_CUBE,
	OBJECT_SPHERE,
	OBJECT_WALL
};




class TilePlane : public tri::TEntity{
public:
	TilePlane(int type = TILE_PLANE);
	virtual ~TilePlane();
	
	virtual void display();
	void deleteModel();
	void setModel(tri::TEntity* mObject);
	
private:
	tri::TEntity* mObject;
	int m_PlaneType;
	float lift;
};



class TileTemplate{
public:
	TileTemplate();
	virtual ~TileTemplate();

	TilePlane* getTile();
	void load(tri::TXMLNode* node);
	unsigned int getID();
	int getTileTypeFromString(std::string t);

private:
	
	std::string mImage;
	std::string mIcon;	
	unsigned int dimensionX;
	unsigned int dimensionY;
	unsigned int mID;
	int mTileType;
	
//	TilePlane mTile;
//	TVector size;
//	TVector pos;
//	TVector rot;
//	TVector scale;
//	float height;
	
//	int ObjectType;
//	std::string mModel;
//	std::map<std::string,std::string> mTextures;
	
	
};


class TileTemplateCache{
public:
	TileTemplateCache();
	virtual ~TileTemplateCache();
	TilePlane* getTile(unsigned int id);
	void getTileTemplateList(std::vector<TileTemplate*> &list);
	void clear();
	void addTemplate(tri::TXMLNode* node);
private:
	std::map<unsigned int, TileTemplate*> mTileTemplateList;
};

}

#endif /*CONTEXT_H_*/
